-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http2: refactor read mechanism #18030
Conversation
@@ -357,6 +357,19 @@ v8::MaybeLocal<v8::Object> New(Environment* env, | |||
// Mixing operator new and free() is undefined behavior so don't do that. | |||
v8::MaybeLocal<v8::Object> New(Environment* env, char* data, size_t length); | |||
|
|||
inline | |||
v8::MaybeLocal<v8::Uint8Array> New(Environment* env, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to explicitly note that a HandleScope must have been opened before calling this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TimothyGu I think that’s kind of explicit in the fact that this returns a MaybeLocal
; that’s never valid without a HandleScope
, right?
(Or, the other way around: The same is true of the other buffer constructors, but we don’t mention it there.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's certainly true. But the other Buffer constructors open a HandleScope themselves so I was wondering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TimothyGu I removed it in this case because, as far as I can tell, all the temporary handles created here refer to objects that are kept alive be the returned Buffer
instance anyway.
If my understanding is correct, I think they could be removed in the other cases as well, but I am not 100 % sure and since some of them are public API I left them the way they were.
test/common/index.js
Outdated
exports.mustCallAsync = function(fn, exact) { | ||
return exports.mustCall((...args) => { | ||
fn(...args).then(exports.mustCall()); | ||
}, exact); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the returned function return a promise as well, so that one could chain the functions returned by mustCallAsync?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TimothyGu yup, done!
lib/perf_hooks.js
Outdated
@@ -467,6 +469,10 @@ function doNotify() { | |||
// Set up the callback used to receive PerformanceObserver notifications | |||
function observersCallback(entry) { | |||
const type = mapTypes(entry.entryType); | |||
|
|||
if (type === NODE_PERFORMANCE_ENTRY_TYPE_HTTP2) | |||
collectStats(entry); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer we didn't define these here, but rather in the HTTP2 part. I think these are also defined for every single instance, which will increase overhead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Did you benchmark this at all? It should yield a nice modest boost.
Add a C++ variant of `Buffer.from(arrayBuffer, offset, length)`.
Refactor the read mechanism to completely avoid copying. Instead of copying individual `DATA` frame contents into buffers, create `ArrayBuffer` instances for all socket reads and emit slices of those `ArrayBuffer`s to JS.
a2c195f
to
d6fcbed
Compare
This is no longer blocked by #18020. CI: https://ci.nodejs.org/job/node-test-commit/15373/ |
@nodejs/benchmarking https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/93/console says
Is there anything we can do about that? |
Ping @nodejs/build |
Add a C++ variant of `Buffer.from(arrayBuffer, offset, length)`. PR-URL: #18030 Reviewed-By: James M Snell <jasnell@gmail.com>
Refactor the read mechanism to completely avoid copying. Instead of copying individual `DATA` frame contents into buffers, create `ArrayBuffer` instances for all socket reads and emit slices of those `ArrayBuffer`s to JS. PR-URL: #18030 Reviewed-By: James M Snell <jasnell@gmail.com>
Add a C++ variant of `Buffer.from(arrayBuffer, offset, length)`. PR-URL: #18030 Reviewed-By: James M Snell <jasnell@gmail.com>
Refactor the read mechanism to completely avoid copying. Instead of copying individual `DATA` frame contents into buffers, create `ArrayBuffer` instances for all socket reads and emit slices of those `ArrayBuffer`s to JS. PR-URL: #18030 Reviewed-By: James M Snell <jasnell@gmail.com>
Add a C++ variant of `Buffer.from(arrayBuffer, offset, length)`. PR-URL: #18030 Reviewed-By: James M Snell <jasnell@gmail.com>
Refactor the read mechanism to completely avoid copying. Instead of copying individual `DATA` frame contents into buffers, create `ArrayBuffer` instances for all socket reads and emit slices of those `ArrayBuffer`s to JS. PR-URL: #18030 Reviewed-By: James M Snell <jasnell@gmail.com>
Should this be backported to |
Add a C++ variant of `Buffer.from(arrayBuffer, offset, length)`. PR-URL: nodejs#18030 Reviewed-By: James M Snell <jasnell@gmail.com>
Refactor the read mechanism to completely avoid copying. Instead of copying individual `DATA` frame contents into buffers, create `ArrayBuffer` instances for all socket reads and emit slices of those `ArrayBuffer`s to JS. PR-URL: nodejs#18030 Reviewed-By: James M Snell <jasnell@gmail.com>
Refactor the read mechanism to completely avoid copying. Instead of copying individual `DATA` frame contents into buffers, create `ArrayBuffer` instances for all socket reads and emit slices of those `ArrayBuffer`s to JS. Backport-PR-URL: #20456 PR-URL: #18030 Reviewed-By: James M Snell <jasnell@gmail.com>
Add a C++ variant of `Buffer.from(arrayBuffer, offset, length)`. PR-URL: nodejs#18030 Reviewed-By: James M Snell <jasnell@gmail.com>
Refactor the read mechanism to completely avoid copying. Instead of copying individual `DATA` frame contents into buffers, create `ArrayBuffer` instances for all socket reads and emit slices of those `ArrayBuffer`s to JS. PR-URL: nodejs#18030 Reviewed-By: James M Snell <jasnell@gmail.com>
The first commit is from #18020 to avoid merge conflicts.src: introduce internal buffer slice constructor
Add a C++ variant of
Buffer.from(arrayBuffer, offset, length)
.http2: refactor read mechanism
Refactor the read mechanism to completely avoid copying.
Instead of copying individual
DATA
frame contents into buffers,create
ArrayBuffer
instances for all socket reads and emitslices of those
ArrayBuffer
s to JS.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
/cc @nodejs/http2